import java.util.Arrays;

public class Test {
    public static boolean oddNum(int[] array){
        boolean result = false;
        for (int i = 0; i <= array.length - 3; i++) {
            if(array[i] % 2 != 0 &&
                    array[i + 1] % 2 != 0 &&
                    array[i + 2] % 2 != 0){
                result = true;
                break;
            }
        }
        return result;
    }

    public static void main(String[] args) {
        int[] array = {2,4,1,3,5,6,7,8,10,12,13};
        boolean result = oddNum(array);
        System.out.println(result);
    }

    //    这个问题可以通过Boyer-Moore投票算法来解决，该算法的基本思想是遍历数组，
//    维护一个候选元素和其出现次数。在遍历过程中，如果当前元素与候选元素相同，
//    则计数加一，否则计数减一。当计数减为零时，说明之前的候选元素不是多数元素，
//    需要更新候选元素为当前元素，并将计数设为一。由于多数元素出现的次数大于 n/2，
//    所以最终候选元素即为所求。
    public static int findMost(int[] array){
        int candidate = array[0];
        int count = 1;

        for (int i = 1; i < array.length; i++) {
            if(array[i] == candidate){
                count++;
            }else{
                count--;
            }

            if(count == 0){
                candidate = array[i];
                count = 1;
            }
        }
        return candidate;
    }

    public static void main8(String[] args) {
        int[] array = {3,3,2,2,3};
        int result = findMost(array);
        System.out.println("多数元素是：" + result);
    }

   public static int singleNum(int[] nums){
       int result = 0;
       for(int num : nums){
           result ^= num;
       }
       return result;
   }

    public static void main7(String[] args) {
        int[] nums = {2,2,1,3,3};
        int result = singleNum(nums);
        System.out.println(result);
    }

    public static void main6(String[] args) {
        int[] nums = {0, 1, 2, 5, 7, 9, 11, 15};
        int target = 9;
        int[] result = twoSum(nums, target);

        if (result != null) {
            System.out.println("[" + result[0] + ", " + result[1] + "]");
        } else {
            System.out.println("未找到满足条件的数对");
        }
    }

    public static int[] twoSum(int[] nums, int target) {
        for (int i = 0; i < nums.length; i++) {
            for (int j = i + 1; j < nums.length; j++) {
                if (nums[i] + nums[j] == target) {
                    return new int[]{i, j};
                }
            }
        }
        return null;
    }

    //   public static int[] addNum(int[] array, int n){
//       for (int i = 0; i < array.length; i++) {
//           for (int j = i + 1; j < array.length; j++) {
//               if(array[i] + array[j] == n){
//                   return new int[] {array[i],array[j]};
//               }
//           }
//       }
//       return null;
//   }
//
//    public static void main5(String[] args) {
//       int[] array = {0,1,2,3,4,5,6,7,8,9};
//       int target = 8;
//       int[] result = addNum(array,target);
//
//       if(result != null){
//           System.out.println("["+ result[0] +","+ result[1] + "]");
//       }else{
//           System.out.println("未找到满足条件的数");
//       }
//    }

    public static void change(int[] arr){
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr.length - 1; j++) {
                if(arr[j] % 2 == 0 && arr[j + 1] % 2 != 0){
                    int num =0;
                    num = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = num;
                }
            }
        }
    }

    public static void main4(String[] args) {
        int[] array = {1,2,3,4,5,6,7,8};
        change(array);
        String newArr = Arrays.toString(array);
        System.out.println(newArr);
    }

    public static void transform(int[] arr){
        for (int i = 0; i < arr.length; i++) {
            arr[i] *= 2;
        }
    }

    public static void main3(String[] args) {
        int[] arr = {1,2,3,4,5,6,7};
        transform(arr);
        for (int num : arr) {
            System.out.print(num + " ");
        }
    }

    public static void hanoi(int n, char from, char to, char aux) {
        if (n == 1) {
            System.out.println("Move disk 1 from " + from + " to " + to);
            return;
        }
        // 将 n-1 个盘子从 from 移动到辅助柱子 aux
        hanoi(n - 1, from, aux, to);
        // 将第 n 个盘子从 from 移动到目标柱子 to
        System.out.println("Move disk " + n + " from " + from + " to " + to);
        // 将 n-1 个盘子从辅助柱子 aux 移动到目标柱子 to
        hanoi(n - 1, aux, to, from);
    }

    public static void main2(String[] args) {
        int n = 3; // 汉诺塔的盘子数量
        char from = 'A', to = 'C', aux = 'B'; // 柱子的名称，A、B、C
        hanoi(n, from, to, aux);
    }


    public static int fib(int n){
        if(n == 1 || n == 2){
            return 1;
        }else{
            return fib(n -1) + fib(n - 2);
        }
    }

    public static void main1(String[] args) {
        int ret = fib(10);
        System.out.println(ret);
    }

}
